<template>
<!--<el-button></el-button>-->
  <div class="login_container">
    <div class="login_box">
      <div class="avatar_box">
        <img src="../assets/logo.png" alt />
      </div>
<!--      登陆表单-->
      <el-form :mode="loginForm" :rules="loginFormRule" label-width="0px" class="login_form">
<!--        用户名-->
        <el-form-item prop="username">
          <el-input v-model="loginForm.username"  prefix-icon="el-icon-user" placeholder="please input the username">
          </el-input>
        </el-form-item>
<!--        密码-->
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" type="password" prefix-icon="el-icon-lock" placeholder="please input the password">
          </el-input>
        </el-form-item>
<!--        按钮-->
        <el-form-item style="margin-left: 25%; margin-top: 10%; ">
          <el-button type="primary" @click="Mylogin">
            登录
          </el-button>
          <el-button type="info" @click="Myreset">
            取消
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data(){
    return{
      // src: "../assets/logo.png"
      loginForm: {
        username: '',
        password: ''
      },

      loginFormRule: {
        //  验证用户名(不使用)
        username: [
          // { required: true, message: '请输入登录名称', trigger: 'blur' },
          {
            // required: true,
            min: 3, max: 7, message: '长度在 3 到 7 个字符', trigger: 'blur' }
        ],
        //  验证密码(不使用)
        password: [
          // { required: true, message: '请输入登录名称', trigger: 'blur' },
          {
            // required: true,
            min: 6,
            max: 15,
            message: '长度在 6 到 15 个字符',
            trigger: 'blur'
          }
        ]
      }
    }

  },
  methods:{
    Mylogin(){
      if(this.loginForm.password.length === 0 || this.loginForm.username.length === 0){
        this.$message.warning("密码和用户名不能为空")
      }
      else if (this.loginForm.password === '123456' && this.loginForm.username === 'admin'){
        // this.$route.path = '/index'
        this.$router.replace({path:'/home'})
      }
      else{
        this.$message.error('密码或者用户名错误');
      }
    },
    Myreset(){
      // this.$refs.loginFromR
      this.loginForm.password = ''
      this.loginForm.username = ''
    }
  }
}
</script>

<style lang="less" scoped>
.login_container{
  background-color: #2c3e50;
  height: 100%;
  width: 100%;
  .login_box{
    width: 40%;
    height: 50%;
    margin-left: 30%;
    margin-top: 10%;
    background-color: #f5ffe4;
    position: absolute;
    .avatar_box {
      width: 100px;
      height: 100px;
      border: 1px solid #eee;
      border-radius: 50%;
      padding: 5px;
      box-shadow: 0 0 5px #ddd;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      background-color: #fff;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #eee;
      }
    }
    .login_form{
      position: absolute;
      bottom: 0;
      width: 100%;
      top: 30%;
      padding: 0 20px;
      box-sizing: border-box;
    }

  }
}
</style>
